package com.springboot.util;

import com.alibaba.fastjson.JSON;
import com.springboot.entity.TbRisReport;
import com.springboot.entity.Zthc;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import java.util.Iterator;

public class paramJx<T> {

    public static Object MyParamJx(String msg){
        try{

            org.dom4j.Document document = DocumentHelper.parseText(msg);
            //获取根节点,在例子中就是responsedata节点
            Element roots = document.getRootElement();

            String method = "";
            String param = "";
            //遍历某个子节点，如resultcode
            for (Iterator i = roots.elementIterator("msgCode"); i.hasNext(); ) {
                Element next = (Element) i.next();
                method =  next.getText();
            }
            String paramxml = "";
            for (Iterator i = roots.elementIterator("msgContent"); i.hasNext(); ) {
                Element next = (Element) i.next();
                paramxml = next.getText();
            }





            Document document1 = DocumentHelper.parseText(paramxml);
            Element roots1 = document1.getRootElement();

            param = roots1.getText();

            param = param.replaceAll("\"彗星尾\"","&quot;彗星尾&quot;");

            if(method.equals("RIS_ADD_Report")){
                TbRisReport tb = JSON.parseObject(param, TbRisReport.class);

                tb.setMethod(method);

                tb.setYxbx(tb.getYxbx().replaceAll("&quot;彗星尾&quot;","\"彗星尾\""));

                return tb;
            }else{
                Zthc zthc = JSON.parseObject(param, Zthc.class);

                zthc.setMethod(method);

                return zthc;
            }



        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
